// Dart imports:
import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:palmf_hid/common/entities/response/base_response.dart';
import 'package:palmf_hid/common/entities/response/curve_entity.dart';
import 'package:palmf_hid/common/utils/net/http_util.dart';
import 'package:palmf_hid/common/utils/utils.dart';
import 'package:palmf_hid/common/values/values.dart';

class ApiRepository {
  ///获取曲线信息
  static Future<List<CurveEntity>> getCurve(
      String batchNo, String sample, String deviceNo) async {
    var param = {
      "token": ApiConstants.tokenV,
      "batchNo": batchNo,
      "sample": sample,
      "deviceNo": deviceNo.trim()
    };
    final res = await HttpUtils.get('/api/bizPalmfCurve/get.json',
        queryParameters: param);
    BaseResponse baseResponse = BaseResponse.fromJson(res.data);
    MyLogUtil().i(param);
    if (baseResponse.code == 0) {
      return baseResponse.data.map<CurveEntity>((json) {
        return CurveEntity.fromJson(json);
      }).toList();
    } else {
      return [];
    }
  }

  /// 结果回传
  static Future<BaseResponse> dataBackup(Map<String, dynamic> data) async {
    MyLogUtil().i(data);
    String platform = "Android";
    if (Platform.isIOS) {
      platform = "IOS";
    }
    data['platform'] = platform;
    FormData formData = FormData.fromMap(
        {"token": ApiConstants.tokenV, "json": jsonEncode(data)});
    final res =
        await HttpUtils.post('/api/bizPalmfTestedInfo/add', data: formData);
    BaseResponse response = BaseResponse.fromJson(res.data);
    MyLogUtil().i("==========================" + response.msg);
    return response;
  }
}
